<script lang="ts" setup>
import {onMounted, ref} from "vue";
import * as echarts from "echarts";
import api from "@/axios";

const loginLogChartDiv = ref();
const genderChartDiv = ref();

onMounted(() => {
  initLoginLogECharDiv(); // 网站访问量
  initGenderChart(); // 员工性别对比图
})

function initLoginLogECharDiv() {
  const myChart = echarts.init(loginLogChartDiv.value);// 图标初始化
  let dateList = [];
  let countList = [];
  api({url: '/selLoginLogChart'}).then(resp => {
    dateList = resp.data.dateList;
    countList = resp.data.countList.map(Number);
    // 绘制图表
    myChart.setOption({
      title: {
        text: '网站访问量'
      },
      tooltip: {},
      xAxis: {
        data: dateList
      },
      yAxis: {},
      series: [{
        name: '访问量',
        type: 'line',
        data: countList
      }]
    });
  });
}

function initGenderChart() {
  const myChart = echarts.init(genderChartDiv.value);// 图标初始化
// 绘制图表
  myChart.setOption({
    title: {
      text: '员工性别对比图'
    },
    tooltip: {},
    xAxis: {
      data: ['男', '女']
    },
    yAxis: {},
    series: [{
      name: '人数',
      type: 'bar',
      data: [5, 20]
    }]
  });
}

</script>

<template>
  <el-row>
    <el-col :span="24">
      <div ref="loginLogChartDiv" :style="{ float: 'left', width: '100%', height: '350px' }"></div>
    </el-col>
  </el-row>
  <el-row>
    <el-col :span="12">
      <div ref="genderChartDiv" :style="{ float: 'left', width: '100%', height: '350px' }"></div>
    </el-col>
    <el-col :span="12">
    </el-col>
  </el-row>

</template>

<style scoped>

</style>